﻿using System;
using System.Collections.Generic;

namespace Shapes
{
    public abstract class Shape
    {
        public abstract double Area { get; }
        public abstract bool IsValid();
    }

    public class Rectangle : Shape
    {
        public double Width { get; set; }
        public double Height { get; set; }

        public override double Area => IsValid() ? Width * Height : 0;

        public override bool IsValid() => Width > 0 && Height > 0;
    }

    public class Square : Shape
    {
        public double Side { get; set; }

        public override double Area => IsValid() ? Side * Side : 0;

        public override bool IsValid() => Side > 0;
    }

    public class Triangle : Shape
    {
        public double Base { get; set; }
        public double Height { get; set; }

        public override double Area => IsValid() ? 0.5 * Base * Height : 0;

        public override bool IsValid() => Base > 0 && Height > 0;
    }
}

namespace ShapeFactoryApp
{
    using Shapes;

    public class ShapeFactory
    {
        private static Random random = new Random();

        public static Shape CreateRandomShape()
        {
            switch (random.Next(3))
            {
                case 0:
                    return new Rectangle { Width = random.Next(1, 10), Height = random.Next(1, 10) };
                case 1:
                    return new Square { Side = random.Next(1, 10) };
                case 2:
                    return new Triangle { Base = random.Next(1, 10), Height = random.Next(1, 10) };
                default:
                    throw new InvalidOperationException();
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            List<Shape> shapes = new List<Shape>();
            double totalArea = 0;

            for (int i = 0; i < 10; i++)
            {
                var shape = ShapeFactory.CreateRandomShape();
                if (shape.IsValid())
                {
                    totalArea += shape.Area;
                }
            }

            Console.WriteLine($"Total Area: {totalArea}");
        }
    }
}